package com.ruoyi.system.service.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.ZhwyTemporarydepositMapper;
import com.ruoyi.system.domain.ZhwyTemporarydeposit;
import com.ruoyi.system.service.IZhwyTemporarydepositService;

/**
 * 临时收费Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-05-07
 */
@Service
public class ZhwyTemporarydepositServiceImpl implements IZhwyTemporarydepositService 
{
    @Autowired
    private ZhwyTemporarydepositMapper zhwyTemporarydepositMapper;

    /**
     * 查询临时收费
     * 
     * @param id 临时收费主键
     * @return 临时收费
     */
    @Override
    public ZhwyTemporarydeposit selectZhwyTemporarydepositById(Long id)
    {
        return zhwyTemporarydepositMapper.selectZhwyTemporarydepositById(id);
    }

    /**
     * 查询临时收费列表
     * 
     * @param zhwyTemporarydeposit 临时收费
     * @return 临时收费
     */
    @Override
    public List<ZhwyTemporarydeposit> selectZhwyTemporarydepositList(ZhwyTemporarydeposit zhwyTemporarydeposit)
    {
        List<ZhwyTemporarydeposit> list = new ArrayList<>();
        List<ZhwyTemporarydeposit> zhwyTemporarydeposits = zhwyTemporarydepositMapper.selectZhwyTemporarydepositList(zhwyTemporarydeposit);
        if (zhwyTemporarydeposit.getBeginTime() != null && zhwyTemporarydeposit.getEndTime() != null){
            for (ZhwyTemporarydeposit temporarydeposit : zhwyTemporarydeposits) {
                Date beginTime = new Date(zhwyTemporarydeposit.getBeginTime());
                Date endTime = new Date(zhwyTemporarydeposit.getEndTime());
                if (temporarydeposit.getChargeTime().after(beginTime) && temporarydeposit.getChargeTime().after(endTime)){
                    list.add(temporarydeposit);
                }
            }
            return list;
        }
        return zhwyTemporarydeposits;
    }

    /**
     * 新增临时收费
     * 
     * @param zhwyTemporarydeposit 临时收费
     * @return 结果
     */
    @Override
    public int insertZhwyTemporarydeposit(ZhwyTemporarydeposit zhwyTemporarydeposit)
    {
        return zhwyTemporarydepositMapper.insertZhwyTemporarydeposit(zhwyTemporarydeposit);
    }

    /**
     * 修改临时收费
     * 
     * @param zhwyTemporarydeposit 临时收费
     * @return 结果
     */
    @Override
    public int updateZhwyTemporarydeposit(ZhwyTemporarydeposit zhwyTemporarydeposit)
    {
        return zhwyTemporarydepositMapper.updateZhwyTemporarydeposit(zhwyTemporarydeposit);
    }

    /**
     * 批量删除临时收费
     * 
     * @param ids 需要删除的临时收费主键
     * @return 结果
     */
    @Override
    public int deleteZhwyTemporarydepositByIds(Long[] ids)
    {
        return zhwyTemporarydepositMapper.deleteZhwyTemporarydepositByIds(ids);
    }

    /**
     * 删除临时收费信息
     * 
     * @param id 临时收费主键
     * @return 结果
     */
    @Override
    public int deleteZhwyTemporarydepositById(Long id)
    {
        return zhwyTemporarydepositMapper.deleteZhwyTemporarydepositById(id);
    }
}
